package cn.cqie.frame.controller;


import cn.cqie.frame.bo.query.QueryEmpEvaluateRecordReqBo;
import cn.cqie.frame.bo.query.QueryStudentEvaluateRecordBo;
import cn.cqie.frame.entity.Emp;
import cn.cqie.frame.entity.EvaluateRecord;
import cn.cqie.frame.entity.EvaluateTask;
import cn.cqie.frame.service.EvaluateRecordService;
import cn.cqie.frame.utils.MyPageHelper;
import cn.cqie.frame.vo.EmpEvaluateRecordVo;
import cn.cqie.frame.vo.EvaluateTargetTreeData;
import cn.cqie.frame.vo.ResultVo;
import cn.cqie.frame.vo.StudentEvaluateRecordVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评教记录 前端控制器
 * </p>
 *
 * @author XYHL
 * @since 2021-10-18
 */
@RestController
@Api("学生评价")
public class EvaluateRecordController {
    @Autowired
    private EvaluateRecordService evaluateRecordService;
    /**
     * 学生评教
     * @param bo
     * @return
     */
    @ApiOperation(value = "学生评教", response = StudentEvaluateRecordVo.class)
    @PostMapping(value = "/listPagedStudentEvaluate")
    public ResultVo<PageInfo<StudentEvaluateRecordVo>> listPagedStudentEvaluate(@RequestBody QueryStudentEvaluateRecordBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(evaluateRecordService.listPagedStudentEvaluate(bo)));
    }

    /**
     * 获取评价任务备选项
     * @return
     */
    @ApiOperation(value = "获取评价任务备选项")
    @GetMapping(value = "/listAllEvaluateTask")
    public ResultVo<List<EvaluateTask>> listAllEvaluateTask(){
        return  ResultVo.success(evaluateRecordService.listAllEvaluateTask());
    }
    /**
     * 评价指标树
     */
    @ApiOperation(value = "评价指标树", notes = "构造elementUi需要的树表数据" )
    @GetMapping("/listEvaluateTargetVoListByEvaluateTypeId")
    public ResultVo<List<EvaluateTargetTreeData>> listTreeEvaluateTarget(Long evaluateTypeId){
        List<EvaluateTargetTreeData> evaluateTargetTreeData = evaluateRecordService.listTreeEvaluateTarget(evaluateTypeId);
        return ResultVo.success(evaluateTargetTreeData);
    }

    /**
     * 保存评价记录
     * @param pos
     * @return
     */
    @ApiOperation(value = "保存评价记录",notes = "批量提交", response = EvaluateRecord.class)
    @PostMapping(value = "/saveRecord")
    public ResultVo<Void> saveRecord (@RequestBody List<EvaluateRecord> pos){
        Boolean aBoolean = evaluateRecordService.saveRecord(pos);
        return aBoolean ? ResultVo.success() : ResultVo.error("保存失败");
    }
    /**
     * 员工评教
     * @param qo
     * @return
     */
    @ApiOperation(value = "员工评教", response = EmpEvaluateRecordVo.class)
    @PostMapping(value = "/listPagedEmpEvaluate")
    ResultVo<PageInfo<EmpEvaluateRecordVo>>listPagedEmpEvaluate(@RequestBody QueryEmpEvaluateRecordReqBo qo){
        List<EmpEvaluateRecordVo> empEvaluateRecordVos = evaluateRecordService.listPagedEmpEvaluate(qo);
        return ResultVo.success(MyPageHelper.returnPage(empEvaluateRecordVos));
    }

    /**
     * 计算分值
     * @param taskId
     */
    @ApiOperation(value = "计算分值")
    @PostMapping(value = "/calculate")
    public void calculate(Long taskId){
        evaluateRecordService.calculateScore(taskId);
    }
}

